/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.unmsm.pacis.shca.domain.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author solriver
 */
@Entity
@Table(name = "provincia", catalog = "bdshca")
@NamedQueries({
    @NamedQuery(name = "Provincia.findAll", query = "SELECT p FROM Provincia p"),
    @NamedQuery(name = "Provincia.findByCcpp", query = "SELECT p FROM Provincia p WHERE p.provinciaPK.ccpp = :ccpp"),
    @NamedQuery(name = "Provincia.findByNombrepp", query = "SELECT p FROM Provincia p WHERE p.nombrepp = :nombrepp"),
    @NamedQuery(name = "Provincia.findByCcdd", query = "SELECT p FROM Provincia p WHERE p.provinciaPK.ccdd = :ccdd")})
public class Province implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProvincePK provincePK;
    @Column(name = "NOMBREPP")
    private String name;
    @JoinColumn(name = "CCDD", referencedColumnName = "CCDD", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Department department;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "province")
    private List<District> districts;

    public Province() {
    }

    public Province(ProvincePK provincePK) {
        this.provincePK = provincePK;
    }

    public Province(String ccpp, String ccdd) {
        this.provincePK = new ProvincePK(ccpp, ccdd);
    }

    public ProvincePK getProvincePK() {
        return provincePK;
    }

    public void setProvincePK(ProvincePK provincePK) {
        this.provincePK = provincePK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public List<District> getDistricts() {
        return districts;
    }

    public void setDistricts(List<District> districts) {
        this.districts = districts;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (provincePK != null ? provincePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Province)) {
            return false;
        }
        Province other = (Province) object;
        if ((this.provincePK == null && other.provincePK != null) || (this.provincePK != null && !this.provincePK.equals(other.provincePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.edu.unmsm.pacis.shca.domain.entity.Province[ provincePK=" + provincePK + " ]";
    }
    
}
